import React from 'react';
import { defaultFormatResult, useRequest } from '@/hooks';
import {
    getEmployeeAssetList,
    getEmployeeVirtualAsset,
    getEmployeeOfficeStationInfo
} from '@/pages/Organization/EmployeeManage/services';
import { Alert, Skeleton } from 'antd';
import AssetsSection from '@/pages/Organization/EmployeeManage/components/EmployeeInfoSections/AssetsSection';
import VirtualAssetsSection from '@/pages/Organization/EmployeeManage/components/EmployeeInfoSections/VirtualAssetsSection';
import OtherAssetsSection from '@/pages/Organization/EmployeeManage/components/EmployeeInfoSections/OtherAssetsSection';

/**
 * 员工详情 - 资产信息
 */
const AssetsTabContent = ({ employeeCode }) => {
    // 固定资产数据
    const { data: assetsData, loading: assetsLoading, error: assetsError } = useRequest(
        () => getEmployeeAssetList({ employeeCode }),
        {
            cacheKey: `employee-assets-${employeeCode}`,
            refreshDeps: [employeeCode],
            ...defaultFormatResult
        }
    );
    // 虚拟资产数据
    const { data: virtualAssetData, loading: virtualAssetLoading, error: virtualAssetError } = useRequest(
        () => getEmployeeVirtualAsset({ employeeCode }),
        {
            cacheKey: `employee-virtualAsset-${employeeCode}`,
            refreshDeps: [employeeCode],
            ...defaultFormatResult
        }
    );
    // 工位数据
    const { data: officeStationData, loading: officeStationLoading, error: officeStationError } = useRequest(
        () => getEmployeeOfficeStationInfo({ employeeCode }),
        {
            cacheKey: `employee-officeStation-${employeeCode}`,
            refreshDeps: [employeeCode],
            ...defaultFormatResult
        }
    );

    // 错误处理
    if (assetsError || virtualAssetError || officeStationError) {
        return <Alert type="error" message={assetsError?.msg || virtualAssetError?.msg || officeStationError?.msg || '数据加载错误'} />;
    }

    // render
    return (
        <>
            <Skeleton loading={!assetsData || assetsLoading} active>
                {/* 固定资产 */}
                <AssetsSection formData={assetsData} />
            </Skeleton>
            <Skeleton loading={!virtualAssetData || virtualAssetLoading} active>
                {/* 虚拟资产 */}
                <VirtualAssetsSection formData={virtualAssetData} />
            </Skeleton>
            <Skeleton loading={!officeStationData || officeStationLoading} active>
                {/* 其他资产 */}
                <OtherAssetsSection formData={officeStationData} />
            </Skeleton>
        </>
    );
};

export default AssetsTabContent;
